package com.xxh.food.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class FileUtils {

    public static String saveFile(MultipartFile uploadFile, String path) throws IOException {
        //上传原文件名
        String uploadName = uploadFile.getOriginalFilename();
        //后缀名获取
        String exts = "."+uploadName.substring(uploadName.lastIndexOf(".") + 1);
        //新文件名
        String fileName  = UUID.randomUUID().toString().trim().replaceAll("-", "").concat(exts);
        //保存文件
        File file = new File(path + fileName);
        uploadFile.transferTo(file);

        return fileName;
    }
}
